import { Type, EventEmitter, TemplateRef } from '@angular/core';
import { Observable } from 'rxjs';

import { PopupComponent } from './popup.component';

export type OnClickCallback<T> = ((instance: T) => (false | void | {}) | Observable<false | void | {}>);

export interface PopupOptions<T = any> {
  title?: string;
  content?: string | TemplateRef<{}> | Type<T>;
  componentParams?: object;
  onSubmit: OnClickCallback<T>;
  onCancel: OnClickCallback<T>;
  width?: number;
}

export abstract class PopupRef<T = any, R = any> {

  abstract popupOpen: EventEmitter<void>;

  abstract popupClose: EventEmitter<R>;

  abstract open(): void;

  abstract close(result?: R): void;

  abstract destroy(result?: R): void;

  abstract triggerSubmit(): void;

  abstract triggerCancel(): void;

  abstract getContentComponent(): T;

  abstract getInstance(): PopupComponent;

}

export interface PopupRes {

  submit(): Observable<any>;

  cancel(): Observable<any>;
}
